#ifndef MYFORMBASE_H
#define MYFORMBASE_H


#include "ui_MyForm.h"
#include <QWidget>
#include <QCloseEvent>
#include <QSettings>
#include <QMenu>
#include "mytranslator.h"
#include "pluginslist.h"
#include "trayicon.h"
#include "SelectPluginButton.h"

class MyFormBase : public QWidget
{
	Q_OBJECT
	Q_PROPERTY(bool uploadedTab READ useUploadedTab WRITE enableUploadedTab RESET restoreUploadedTab);
	Q_PROPERTY(bool autoCopy READ autoCopy WRITE autoCopyToggled RESET restoreAutoCopy);
	Q_PROPERTY(bool useHtml READ useHtml WRITE setUseHtml RESET resetUseHtml);
	Q_PROPERTY(bool dontClearQueue READ dontClearQueue WRITE setDontClearQueue RESET resetDontClearQueue);

public:
	MyFormBase(QWidget *parent = 0);
	~MyFormBase();

// Properties
private slots:
	void enableUploadedTab(const bool enable);
	void autoCopyToggled(const bool enabled);
	void setUseHtml(const bool enable);
	void setDontClearQueue(const bool enable);
protected:
	inline void sinchronizeCheckBox(QAbstractButton *checkBox, const bool enable) {
		if ( checkBox->isChecked() != enable )
			checkBox->setChecked(enable);
	}
	inline bool useUploadedTab() const { return Config->value("uploadedTab", false).toBool(); }
	inline void restoreUploadedTab() { enableUploadedTab(useUploadedTab()); }
	inline bool autoCopy() const { return Config->value("autoCopy", true).toBool(); }
	inline void restoreAutoCopy() { autoCopyToggled(autoCopy()); }
	inline bool useHtml() const { return Config->value("useHtml", true).toBool(); }
	inline void resetUseHtml() { setUseHtml(useHtml()); }
	inline bool dontClearQueue() const { return Config->value("dontClearQueue", false).toBool(); }
	inline void resetDontClearQueue() { setDontClearQueue(dontClearQueue()); }

protected:
// Needful things
	QSettings *Config;
	Ui::MyForm ui;
	MyTranslator trans;
private:
	void loadLangs();
	void restoreLang();
	//
	bool needQuit; // when quit action selected
	//
	TrayIcon *trayIcon;
	void createTrayIcon();
	void closeEvent(QCloseEvent *event);
private slots:
	void prevStackedWidget() const; // select which input plugin buttons are displayed
	void nextStackedWidget() const;
	void saveResTemplate() const;
	void trayAction(const QSystemTrayIcon::ActivationReason reason);
	inline void retranslateUi() { ui.retranslateUi(this); }
	inline void saveSettingsTabSelected(const int index) const { Config->setValue("currentSettingsTab", index); }
	inline void quit() {
		this->needQuit = true;
		this->close();
	}

protected slots:
	inline void addPluginButton(SelectPluginButton *button) const { ui.selectPluginBox->layout()->addWidget(button); }
	inline void addSettingsTab(QWidget* tab, const QIcon &icon, const QString &label) const { ui.toolBox->addItem(tab, icon, label); }
	inline void setUploadIcon(const QIcon &icon) const {
		ui.UploadButton->setIcon(icon);
		ui.actionStart->setIcon(icon);
	}
	// Not used here but called from ui
	virtual void upload() = 0;
	virtual void setResultLabelText() const = 0;
	virtual void enableUploadButton(const bool enable = true) = 0;
	virtual void disableUploadButton(const bool disable = true) = 0;

};

#endif // MYFORMBASE_H
